<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<html>
<head>
    <title>技术论坛系统</title>
    <link href="/css/bootstrap.css" rel="stylesheet">
    <link href="/css/style.css" rel="stylesheet">


</head>
<body style="background-color: #fafafa">
<script type="text/javascript" src="/js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="/js/bootstrap.js"></script>
<div class="container-fluid">
    <img src="/img/navback.jpg" alt="..." class="note-img">
    <div class="row">
        <div class="col-md-3">
            <ul class="list-group">
                <li class="list-group-item"><a href="${pageContext.request.contextPath}/api/admin/">分类管理</a></li>
                <li class="list-group-item active">帖子管理</li>

            </ul>

        </div>

        <div class="col-md-9" style="background-color: white;">

            <table class="table table-hover">
                <tr class="manage-item">
                    <th>id</th>
                    <th>标题</th>
                    <th>作者</th>
                    <th>标题颜色</th>
                    <th>置顶</th>
                    <th>精华</th>
                    <th>操作</th>
                </tr>
                <c:forEach items="${notes}" var="note">
                    <tr>
                        <td>${note.noteid}</td>
                        <td>
                            <input type="text" value="${note.notename}" id="notename${note.noteid}">
                        </td>
                        <td>${note.createby}</td>
                        <td><input type="text" value="${note.tittlecolor}" id="tittlecolor${note.noteid}"></td>
                        <td>
                            <c:if test="${note.top==1}">
                                <input type="checkbox" name="isTop" checked="checked" onchange="setTop(${note.noteid},${note.top})">
                            </c:if>
                            <c:if test="${note.top!=1}">
                                <input type="checkbox" name="isTop" onchange="setTop(${note.noteid},${note.top})">
                            </c:if>
                        </td>
                        <td>
                            <c:if test="${note.isgood==1}">
                                <input type="checkbox" name="isGood" checked="checked" onchange="setGood(${note.noteid},${note.isgood})">
                            </c:if>
                            <c:if test="${note.isgood!=1}">
                                <input type="checkbox" name="isGood" onchange="setGood(${note.noteid},${note.isgood})">
                            </c:if>
                        </td>
                        <td>
                            <a href="#" onclick="updateNoteName(${note.noteid})">修改标题</a>
                            <a href="#" onclick="updateColor(${note.noteid})">加亮</a>
                            <a href="#" onclick="getNote(${note.noteid})" data-toggle="modal" data-target="#myModal">修改内容</a>
                            <a href="#" onclick="deleteNote(${note.noteid})">删除</a>
                            <a href="${pageContext.request.contextPath}/api/admin/manageComment?noteid=${note.noteid}">查看评论</a>
                        </td>
                    </tr>
                </c:forEach>
            </table>

        </div>

    </div>


</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">内容</h4>
            </div>
            <div class="modal-body">
                <input style="display: none" id="note-edit-id">
                <textarea class="form-control" rows="4" id="note"></textarea>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" onclick="editSave()" class="btn btn-primary">Save changes</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function updateNoteName(noteid) {
        var notename = $("#notename"+noteid).val();
        $.post("${pageContext.request.contextPath}/api/admin/note/edit",{"noteName":notename,"noteId":noteid},function (data) {
            if (data.success==1){
                alert("修改成功！");
                window.location.reload();
            } else{
                alert("修改失败！");
            }
        })
    }
    function updateColor(noteid) {
        var notename = $("#tittlecolor"+noteid).val();
        $.post("${pageContext.request.contextPath}/api/admin/note/note/setLight",{"tittleColor":notename,"noteId":noteid},function (data) {
            if (data.success==1){
                alert("修改成功！");
                window.location.reload();
            } else{
                alert("修改失败！");
            }
        })
    }

    function getNote(noteid) {
        $.post("${pageContext.request.contextPath}/api/admin/note/",{"noteId":noteid},function (data) {
            $("#note").val(data.data.text)
            $("#note-edit-id").val(noteid)
        })
    }

    function setTop(noteid,top) {
        $.post("${pageContext.request.contextPath}/api/admin/note/setTop",{"noteId":noteid,"top":top}
        ,function (data) {
                if (data.success==1){
                    alert("修改成功！");
                    window.location.reload();
                } else{
                    alert("修改失败！");
                }
        })
    }

    function setGood (noteid,isgood) {
        $.post("${pageContext.request.contextPath}/api/admin/note/setGood",{"noteId":noteid,"isGood":isgood},function (data) {
            if (data.success==1){
                alert("修改成功！");
                window.location.reload();
            } else{
                alert("修改失败！");
            }
        })
    }

    function editSave() {
        var noteid = $("#note-edit-id").val()
        var text = $("#note").val()
        $.post("${pageContext.request.contextPath}/api/admin/note/edit",{"note":text,"noteId":noteid},function (data) {
            if (data.success==1){
                alert("修改成功！");
                window.location.reload();
            } else{
                alert("修改失败！");
            }
        })
    }

    function deleteNote(noteid) {
        $.post("${pageContext.request.contextPath}/api/admin/note/delete",{"noteId":noteid},function (data) {
            if (data.success==1){
                alert("删除成功！");
                window.location.reload();
            } else{
                alert("删除失败！");
            }
        })
    }
</script>
</body>
</html>
